package com.chen.bpsptsystem.controller.manger;

import com.chen.bpsptsystem.common.ServerResponse;
import com.chen.bpsptsystem.po.Material;
import com.chen.bpsptsystem.service.IMaterialService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学习资料controller
 *
 * @author chen
 */

@RestController
@RequestMapping("/back/material/")
public class MaterialController {

    @Resource
    private IMaterialService materialService;

    /**
     * 资料添加
     */
    @PostMapping("add")
    public ServerResponse add(@RequestBody Material material) {
        return materialService.add(material);
    }

    /**
     * 班级资料list
     */
    @GetMapping("list")
    public ServerResponse list(@RequestParam(value = "pn", name = "pn", defaultValue = "1") Integer pn,
                               @RequestParam(value = "pageSize", name = "pageSize", defaultValue = "10") Integer pageSize,
                               @RequestParam(name = "clazzId", value = "clazzId") String clazzId) {
        return materialService.list(pn, pageSize, clazzId);
    }

    /**
     * 资料修改
     */
    @PostMapping("edit")
    public ServerResponse edit(@RequestBody Material material) {
        return materialService.edit(material);
    }

    /**
     * 资料删除
     */
    @PostMapping("delete")
    public ServerResponse delete(Integer mId) {
        return materialService.delete(mId);
    }

    /**
     * 将兴趣班资料分配给该兴趣班用户
     *
     * @param clazzId 班级id
     * @param mIds    资料ids
     */
    @PostMapping("distribution")
    public ServerResponse distribution(Integer clazzId, String mIds) {
        return materialService.distribution(clazzId, mIds);
    }
}
